<?php
header("Content-type:text/html; charset=utf-8;");
require '../../../ppf/fun.php';
require '../../../ppf/pdo_mysql.php';
require '../../../ppf/Filter.php';

$pd=new pdo_mysql();
$filter=new Filter();
session_start();

if(empty($_SESSION['uid'])){
    $tips=array(
		'tips'=>'请登录后再进行操作',
		'url'=>'./?t=login'
	);
	$tips=urlencode(serialize($tips));
	header('Location:../tips.php?gets='.$tips);
	exit;
}

$submitMethod=$_SERVER["REQUEST_METHOD"];
if($submitMethod=='POST'){
    $now=date('Y-m-d H:i:s');
    $id       =empty($_POST['id'])?0:Filter::filter_number($_POST['id']);
	$grpname  = Filter::safe_string($_POST['grpname']);
	$mech        =empty($_POST['mech'])?0:Filter::filter_number($_POST['mech']);
	$flag     =empty($_POST['flag'])?0:Filter::filter_number($_POST['flag']);

	$in_data=array(
		'grpname' =>$grpname,
		'mech'   =>$mech,
		'flag'   =>$flag
	);
	$result=0;
	$tps='';
	if($id==0){
		$result=$pd->insert(array('data'=>$in_data,'table'=>'sys_custom_group'));
		$tps='添加成功';
	}else{
		$result=$pd->update(array('data'=>$in_data,'table'=>'sys_custom_group','where'=>"id=".$id));
		$tps='修改成功';
	}
	if(empty($result)){
		echo "ok";exit;
	}else{
		echo "ok";exit;
	}
}else{
	echo "不允许的表单提交方式，请按正常流程提交表单。";exit;
}
?>